"use strict";
import {ChinaUnicomSDK} from "@/utils/callcenter/sdk/ChinaUnicomSDK";


try {
  new ChinaUnicomSDK("https://10.128.108.15:9978/sdk/china-unicom/iframe.html");
} catch (e) {
  console.log(e);
}
const ProviderDic = {
  "ChinaUnicom": new ChinaUnicomSDK("https://10.128.108.15:9978/sdk/china-unicom/iframe.html"),
}


/**
 * 1. 事件处理
 * 需要关注的事件
 * 系统事件: 1.SDK加载成功 2.登录成功 3.登录失败 4.登出
 * 电话事件: 5.呼出 6.呼入 7.客户接通 8.挂断
 *
 * 2.
 */
export default class CallCenterSdk {
  //连接SDK成功
  static EVENT_FRAME_CONNECT_SUCCESS = "EVENT_FRAME_CONNECT_SUCCESS";
  //SDK加载完毕
  static EVENT_SDK_LOADED_SUCCESS = "EVENT_SDK_LOADED_SUCCESS";
  //座席登录成功
  static EVENT_LOGIN_SUCCESS = "EVENT_LOGIN_SUCCESS";
  //座席登录失败
  static EVENT_LOGIN_FAIL = "EVENT_LOGIN_FAIL";
  //座席登出
  static EVENT_LOGOUT = "EVENT_LOGOUT";
  //呼出中
  static EVENT_CALL_OUT_COMING = "EVENT_CALL_OUT_COMING";
  //呼入中
  static EVENT_CALL_IN_COMING = "EVENT_CALL_IN_COMING";
  //已经接通
  static EVENT_CALL_CONNECTED = "EVENT_CALL_CONNECTED";
  //已经挂断
  static EVENT_CALL_TERMINATED = "EVENT_CALL_TERMINATED";
  //拨打记录事件
  static EVENT_CALL_RECORD = "EVENT_CALL_RECORD";
  //话单事件
  static EVENT_CALL_INFO = "EVENT_CALL_INFO";
  //登录成功&软电话准备就绪
  static EVENT_LOGIN_SUCCESS = "EVENT_LOGIN_SUCCESS";
  //登录失败&记录失败原因
  static EVENT_LOGIN_FAIL = "EVENT_LOGIN_FAIL";
  //登出
  static EVENT_LOGOUT = "EVENT_LOGOUT";
  //电话事件:正在呼出
  static EVENT_CALL_INCOMING = "EVENT_CALL_INCOMING";
  //电话事件:客户已经接通
  static EVENT_CALL_CONNECTED = "EVENT_CALL_CONNECTED";
  //电话事件:挂断
  static EVENT_CALL_TERMINATED = "EVENT_CALL_TERMINATED";

  //记录状态信息
  state = {
    SDK_LOADED_START_TIME: -1,
    SDK_LOADED: false,
    LOGIN: false,
  }


  //记录Lisener
  listener = {}
  provider = null;
  isInit = false;

  constructor(providerName) {
    this.provider = ProviderDic[providerName];
  }

  // /**
  //  * 检查状态信息
  //  */
  // checkState() {
  //   if (!this.state.SDK_LOADED) {
  //
  //   }
  // }

  /**
   *
   */
  init = function () {
    if (this.isInit === false) {
      this.provider.init();
    } else {
      this.isInit = false;
    }
  }

  /**
   * 登录
   * @param info
   */
  login = function (info) {
    this.provider.login(info);
  }
  /**
   * 拨打电话
   * @param bizId
   * @param number
   */
  makeCall = function (bizId, number, callRegistno, callAcntName, callAcntCode, callAcntTypeCode, calledName) {
    this.provider.makeCall(bizId, number, callRegistno, callAcntName, callAcntCode, callAcntTypeCode, calledName);
  }
  /**
   * 取消拨打电话
   */
  cancelCall = function () {
    this.provider.cancelCall();
  }
  pickUp = function () {
    this.provider.pickUp();
  }

  addEventListener(name, handler) {
    this.provider.addEventListener(name, handler);
  }


}
